﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.Operation.Buffer.Validate
{
	public class PointPairDistance
	{
		public void Initialize()
		{
			this._isNull = true;
		}

		public void Initialize(Coordinate p0, Coordinate p1)
		{
			this._pt[0].CoordinateValue = p0;
			this._pt[1].CoordinateValue = p1;
			this._distance = p0.Distance(p1);
			this._isNull = false;
		}

		private void Initialize(Coordinate p0, Coordinate p1, double distance)
		{
			this._pt[0].CoordinateValue = p0;
			this._pt[1].CoordinateValue = p1;
			this._distance = distance;
			this._isNull = false;
		}

		public double Distance
		{
			get
			{
				return this._distance;
			}
		}

		public Coordinate[] Coordinates
		{
			get
			{
				return this._pt;
			}
		}

		public Coordinate GetCoordinate(int i)
		{
			return this._pt[i];
		}

		public void SetMaximum(PointPairDistance ptDist)
		{
			this.SetMaximum(ptDist._pt[0], ptDist._pt[1]);
		}

		public void SetMaximum(Coordinate p0, Coordinate p1)
		{
			if (this._isNull)
			{
				this.Initialize(p0, p1);
				return;
			}
			double num = p0.Distance(p1);
			if (num > this._distance)
			{
				this.Initialize(p0, p1, num);
			}
		}

		public void SetMinimum(PointPairDistance ptDist)
		{
			this.SetMinimum(ptDist._pt[0], ptDist._pt[1]);
		}

		public void SetMinimum(Coordinate p0, Coordinate p1)
		{
			if (this._isNull)
			{
				this.Initialize(p0, p1);
				return;
			}
			double num = p0.Distance(p1);
			if (num < this._distance)
			{
				this.Initialize(p0, p1, num);
			}
		}

		private readonly Coordinate[] _pt = new Coordinate[]
		{
			new Coordinate(),
			new Coordinate()
		};

		private double _distance = double.NaN;

		private bool _isNull = true;
	}
}
